﻿using EnvDTE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VSIXCodeCreate
{
    /// <summary>
    /// 公共处理工具类
    /// </summary>
    public class CommonUtils
    {
        public static string GetActiveDocumentCode()
        {
            // 获取 DTE 对象
            var dte = (DTE)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(DTE));

            // 获取当前活动文档
            Document activeDoc = dte.ActiveDocument;
            if (activeDoc == null) return null;

            // 获取文本内容
            TextDocument textDoc = (TextDocument)activeDoc.Object("TextDocument");
            EditPoint editPoint = textDoc.StartPoint.CreateEditPoint();
            return editPoint.GetText(textDoc.EndPoint);
        }
    }
}
